package com.hspedu.tankgame5;

import java.util.Vector;

/**
 * @author DL5O
 * @version 1.0
 */
public class Tank {
    private int x;//坦克的坐标，这个坐标很重要，用来绘制坦克，移动等都考这个
    private int y;
    private int direct;//坦克方向
    private int speed;//移动速度
    private int shotSpeed = 20;//子弹的设计速度
    boolean isLive = true;//生命周期
    Vector<Shot> shots = new Vector<>();

    public Tank(int x, int y, int direct, int speed, int shotSpeed) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.speed = speed;
        this.shotSpeed = shotSpeed;
    }

    public Tank(int x, int y, int direct, int speed) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.speed = speed;
    }

    //坦克移动
    public void moveUp() {
        y -= speed;
    }

    public void moveRight() {
        x += speed;
    }

    public void moveDown() {
        y += speed;
    }

    public void moveLeft() {
        x -= speed;
    }

    //坦克射击行为
    public void shotTank() {
        Shot shot = null;
        switch (getDirect()) {
            case 0://上
                shot = new Shot(x + 20, y, 0);
                break;
            case 1://上
                shot = new Shot(x + 60, y + 20, 1);
                break;
            case 2:
                shot = new Shot(x,y+20,2);
                break;
            case 3:
                shot = new Shot(x,y+20,3);
                break;
        }
        shots.add(shot);
        new Thread(shot).start();
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getShotSpeed() {
        return shotSpeed;
    }

    public void setShotSpeed(int shotSpeed) {
        this.shotSpeed = shotSpeed;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }
}
